﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Tool
{

    public partial class Form1 : Form
    {
        [DllImport("Engine")]
        public static extern int RendererLoadShader(string filename);
        [DllImport("Engine")]
        public static extern int RendererLoadTexture(string filename);
        [DllImport("Engine")]
        public static extern int RendererLoadMesh(string filename);
        [DllImport("Engine")]
        public static extern int RendererAddInstance(int shader, int texture, int mesh);
        [DllImport("Engine")]
        public static extern void RendererCameraRotate(float x, float y, float z);
        [DllImport("Engine")]
        public static extern void RendererCameraTranslate(float x, float y, float z);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RendererAddInstance(shaderComboBox.SelectedIndex, textureComboBox.SelectedIndex, meshComboBox.SelectedIndex);
        }

        private void buttonShader_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                int result = RendererLoadShader(dlg.FileName);

                if(result != -1)
                    shaderComboBox.Items.Add(dlg.SafeFileName);
            }
        }

        private void buttonTexture_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                int result = RendererLoadTexture(dlg.FileName);

                if(result != -1)
                    textureComboBox.Items.Add(dlg.SafeFileName);
            }

        }

        private void buttonMesh_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                int result = RendererLoadMesh(dlg.FileName);
                
                if(result != -1)
                    meshComboBox.Items.Add(dlg.SafeFileName);
            }

        }

        private void buttonLoadCube_Click(object sender, EventArgs e)
        {
            int result = RendererLoadMesh(null);

            if (result != -1)
                meshComboBox.Items.Add("Cube");
        }

        private void buttonCamUp_Click(object sender, MouseEventArgs e)
        {
            RendererCameraRotate(1.0f, 0.0f, 0.0f);
        }

        private void buttonCamDown_Click(object sender, MouseEventArgs e)
        {
            RendererCameraRotate(-1.0f, 0.0f, 0.0f);
        }

        private void buttonCamRight_Click(object sender, MouseEventArgs e)
        {
            RendererCameraRotate(0.0f, -1.0f, 0.0f);
        }

        private void buttonCamLeft_Click(object sender, MouseEventArgs e)
        {
            RendererCameraRotate(0.0f, 1.0f, 0.0f);
        }

        /*
        float deltaX = 0;
        float deltaY = 0;

        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            deltaX = e.X;
            deltaY = e.Y;
           
        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            deltaX = e.X - deltaX;
            deltaY = e.Y - deltaY;

            RendererCameraRotate(deltaX, deltaY, 0.0f);
        }
         */
    }
}
